home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / gengetopt-2.6.lha / gengetopt-2.6 / src / parser.y < prev    next >
Text File  |  2002-03-02  |  4KB  |  138 lines

  1. /**
  2.  * Copyright (C) 1999, 2000, 2001  Free Software Foundation, Inc.
  3.  *
  4.  * This file is part of GNU gengetopt 
  5.  *
  6.  * GNU gengetopt is free software; you can redistribute it and/or modify 
  7.  * it under the terms of the GNU General Public License as published by 
  8.  * the Free Software Foundation; either version 2, or (at your option) 
  9.  * any later version. 
  10.  *
  11.  * GNU gengetopt is distributed in the hope that it will be useful, but 
  12.  * WITHOUT ANY WARRANTY; without even the implied warranty of 
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  14.  * Public License for more details. 
  15.  *
  16.  * You should have received a copy of the GNU General Public License along 
  17.  * with gengetopt; see the file COPYING. If not, write to the Free Software 
  18.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  19.  */
  20.  
  21.  
  22. %{
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26.  
  27. #include "argsdef.h"
  28.  
  29. #include "gengetopt.h"
  30.  
  31. extern int gengetopt_count_line;
  32.  
  33. static int gengetopt_package_given = 0;
  34. static int gengetopt_version_given = 0;
  35. static int gengetopt_purpose_given = 0;
  36.  
  37. extern void yyerror ( char *error ) ;
  38. extern int yylex () ;
  39.  
  40. #define YYERROR_VERBOSE 1
  41. #define check_result \
  42.     if (o) { switch (o) { case 1: yyerror ("not enough memory"); break; case 2: yyerror ("long option redefined"); break; case 3: yyerror ("short option redefined"); break; case 4: yyerror ("bug found!!"); break; } YYERROR; }
  43. %}
  44.  
  45. %union {
  46. char * str;
  47. char chr;
  48. int argtype;
  49. int bool;
  50. }
  51.  
  52. %token           TOK_PACKAGE
  53. %token           TOK_VERSION
  54. %token           TOK_OPTION
  55. %token           TOK_YES
  56. %token           TOK_NO
  57. %token           TOK_FLAG
  58. %token           TOK_PURPOSE
  59. %token <bool>    TOK_ONOFF
  60. %token <str>     TOK_STRING
  61. %token           TOK_DEFAULT
  62. %token <str>     TOK_MLSTRING
  63. %token <chr>     TOK_CHAR
  64. %token <argtype> TOK_ARGTYPE
  65. %type  <str>     exp_str
  66. %type  <str>     exp_mlstr
  67. %type  <bool>    exp_yesno
  68. %type  <str>     def_value
  69.  
  70.  
  71. %%
  72.  
  73.  
  74. input:    
  75.     | input exp
  76. ;
  77.  
  78.  
  79. exp_str:     TOK_STRING             { $$ = $1; }
  80. ;
  81.  
  82. exp_mlstr:     TOK_MLSTRING           { $$ = $1; }
  83. ;
  84.  
  85.  
  86. exp_yesno:      TOK_YES  { $$ = 1; }
  87.         | TOK_NO   { $$ = 0; }
  88. ;
  89.  
  90.  
  91. exp: TOK_PACKAGE TOK_STRING { if (gengetopt_package_given) { yyerror ("package redefined"); YYERROR; } else { gengetopt_package_given = 1; if (gengetopt_define_package ($2)) { yyerror ("not enough memory"); YYERROR; } } }
  92. ;
  93.  
  94.  
  95. exp: TOK_VERSION TOK_STRING { if (gengetopt_version_given) { yyerror ("version redefined"); YYERROR; } else { gengetopt_version_given = 1; if (gengetopt_define_version ($2)) { yyerror ("not enough memory"); YYERROR; } } }
  96. ;
  97.  
  98. exp: TOK_PURPOSE exp_mlstr { if (gengetopt_purpose_given) { yyerror ("purpose redefined"); YYERROR; } else { gengetopt_purpose_given = 1; if (gengetopt_define_purpose ($2)) { yyerror ("not enough memory"); YYERROR; } } }
  99. ;
  100.  
  101. exp: TOK_PURPOSE exp_str { if (gengetopt_purpose_given) { yyerror ("purpose redefined"); YYERROR; } else { gengetopt_purpose_given = 1; if (gengetopt_define_purpose ($2)) { yyerror ("not enough memory"); YYERROR; } } }
  102. ;
  103. exp: TOK_OPTION TOK_STRING TOK_CHAR exp_str TOK_NO { int o = gengetopt_add_option ($2, $3, $4, ARG_NO, 0, 0, 0); check_result; }
  104. ;
  105.  
  106.  
  107. exp: TOK_OPTION TOK_STRING TOK_CHAR exp_str TOK_FLAG TOK_ONOFF { int o = gengetopt_add_option ($2, $3, $4, ARG_FLAG, $6, 0, 0); check_result; }
  108. ;
  109.  
  110.      
  111. exp: TOK_OPTION TOK_STRING TOK_CHAR exp_str TOK_ARGTYPE exp_yesno { int o = gengetopt_add_option ($2, $3, $4, $5, 0, $6, 0); check_result; }
  112. ;
  113.  
  114. exp: TOK_OPTION TOK_STRING TOK_CHAR exp_str TOK_ARGTYPE def_value exp_yesno 
  115.   int o = gengetopt_add_option ($2, $3, $4, $5, 0, $7, $6); 
  116.   check_result; 
  117.   if ($6 != 0 && 
  118.       ($5 == ARG_FLOAT || $5 == ARG_DOUBLE || $5 == ARG_LONGDOUBLE))
  119.     {
  120.       fprintf 
  121.         (stderr, 
  122.          "gengetopt: %d: Warning: default values may not work correctly with "
  123.          "type %s\n", gengetopt_count_line, arg_names [$5]);
  124.       fprintf
  125.         (stderr, "This problem will be fixed in future releases.\n");
  126.     }
  127. }
  128. ;
  129.  
  130. def_value: { $$ = 0; }
  131.          | TOK_DEFAULT '=' TOK_STRING { $$ = $3; }
  132. ;
  133.  
  134. %%
  135.  
  136.  
  137.